package cn.cjxy.controller;

import cn.cjxy.domain.TitleHot;
import cn.cjxy.service.TitleService;
import cn.cjxy.utils.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
@CrossOrigin//解决跨域
@RestController
@RequestMapping("/hot")
public class HotController {

    @Autowired
    private TitleService titleService;



    /**
     * 跟据时间段统计热度前10
     * @return
     * @throws IOException
     */
    @RequestMapping("/top")
    public List<TitleHot> top(@RequestBody Query query) throws IOException {
        return titleService.findTitleByTimeStamp(query.getStart(), query.getEnd());
    }

    /**
     * 根据时间段统计热度前10，且分终端
     * @param query
     * @return
     * @throws IOException
     */
    @RequestMapping("/count")
    public List<TitleHot> count(@RequestBody Query query) throws IOException {

        List<TitleHot> titleByTimeStampAndAgent = titleService.findTitleByTimeStampAndAgent(query.getStart(), query.getEnd(), query.getAgent());
        System.out.println(titleByTimeStampAndAgent);
        return titleByTimeStampAndAgent;
    }
}
